'''
Created on Jan 29, 2010

@author: madsk
'''

from PyQt4 import QtGui, QtCore

class ScaleDialog(QtGui.QDialog):
    RESOLUTIONS = [(800,480), (1200,720), (1600,960)]
    def __init__(self, parent=None):
        super(ScaleDialog, self).__init__(parent)
        
        self._vbox = QtGui.QVBoxLayout(self)
        self.setLayout(self._vbox)

        self._vbox.addWidget(QtGui.QLabel("Select desired dimensions."))
        
        self._resolutionList = QtGui.QListWidget()
        for resolution in ScaleDialog.RESOLUTIONS:
            self._resolutionList.addItem("%ix%i"%resolution)
        self._vbox.addWidget(self._resolutionList)
        
        self._buttonbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|
                                                 QtGui.QDialogButtonBox.Cancel)
        self._vbox.addWidget(self._buttonbox)
        
        self._buttonbox.clicked.connect(self._handleButtonClicked)
        
    def _handleButtonClicked(self, button):
        if self._buttonbox.standardButton(button) == QtGui.QDialogButtonBox.Ok:
            self.done(1)
        else:
            self.done(0)
            
    def getResolution(self):
        res = str(self._resolutionList.currentItem().text())
        x, y = res.split('x')
        return (int(x), int(y))